import type { ThemeConfigProp } from '../store/interface'

const useTheme = (themeConfig: ThemeConfigProp) => {
  const { weakOrGray, isDark } = themeConfig
  const initTheme = () => {
    // 灰色和弱色切换
    const body = document.documentElement as HTMLElement
    if (!weakOrGray) body.setAttribute('style', '')
    if (weakOrGray === 'gray') body.setAttribute('style', 'filter: grayscale(1)');
    if (weakOrGray === 'weak') body.setAttribute('style', 'filter: invert(80%)');
      // 切换暗黑模式
      (document.getElementById('themeStyle') as HTMLLinkElement).href = isDark ? '/style/dark-theme.css' : '/style/default-theme.css';
  }
  initTheme();
  return {
    initTheme,
  }
}

export default useTheme;